function _view(id){
	var parameter = new Object();
	parameter["docId"] = id;
	jQuery.ajax({
	    type: "GET",
		cache: false,
		data:parameter,
		url: i1510.contextPath+"/admin/mflowTpl/view.do",
		dataType:'json',
		success: function(value){
			var dataList = value.data;
			var dataInput = $("#sumbitForm").find(":input");
			$.each(dataInput, function(i, item) {
				if(item.type == "radio" ){
					if(item.value == dataList[item.name]){
						$("#"+item.id).attr("checked","");
					}else{
						$("#"+item.id).removeAttr("checked");
					}
				}else{
					item.value = dataList[item.name];					
				}
			});
			
		},		       
        error: function(jqXHR , textStatus , errorThrown){
        	alert("error");
        }
	})
}
function _submit(){
		var $result = $('#events-result');
		jQuery.ajax({
		    type: "POST",
			cache: false,
			data:$('#sumbitForm').serialize(),
			url: i1510.contextPath + "/admin/mflowTpl/save.do",
			dataType:'json',
			success: function(value){
				if(value.result == "success" && value.code == "1"){
					$result.removeClass("alert-danger");
					$result.addClass("alert-info");
					$result.text("提示:提交成功!");
					setTimeout("_hidePop();", 3000);						
				}else{
					$result.removeClass("alert-info");
					$result.addClass("alert-danger");
					$result.text("提示:提交失败!");
				}
			},		       
	        error: function(jqXHR , textStatus , errorThrown){
				$result.removeClass("alert-info");
				$result.addClass("alert-danger");
				$result.text("提示:提交失败!");
	        }
		})
}
function _hidePop(){
	$('#info-pop').popover('hide');
}
$(function () {
	var id = $("#docId").val();
	if(id != null && id != ""){
		_view(id);
	}
	jQuery("#btn_submit").bind("click",_submit);
});